package pdm.yamba;

import java.util.List;

import pdm.yamba.dto.Status;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class DetailActivity extends Activity {

	private MainApplication application;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_timeline_detail);

		application = (MainApplication) getApplication();
		
		// Retrieve the index of the status stored in memory
		Intent intent = getIntent();
		int statusIndex = Integer.parseInt(intent.getStringExtra("statusIndex"));
		List<Status> statuses = application.getStatuses();
		
		// Retrieve the status from memory with the provided id
		Status status = statuses.get(statusIndex);
		
		// Display the status:
        // Get the text boxes from the layout (activity_timeline_detail.xml) 
        // and assign the values from the object (TimelineItem)
		TextView idText = (TextView) findViewById(R.id.idText);
		idText.setText(String.valueOf(status.getId()));		
		
        TextView statusText = (TextView) findViewById(R.id.statusText);
        statusText.setText(status.getMessage());        
        
        TextView authorText = (TextView) findViewById(R.id.authorText);
        authorText.setText(status.getAuthor());        
        
        TextView publishDateText = (TextView) findViewById(R.id.publishDateText);
        publishDateText.setText(String.valueOf(status.getPublishDate())); 
        
       
		Button btnSendEMail = (Button)this.findViewById(R.id.btnSendEMail);
		btnSendEMail.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {        
				
		        TextView statusText = (TextView) findViewById(R.id.statusText);
		        
				Intent email = new Intent(Intent.ACTION_SEND);
				email.putExtra(Intent.EXTRA_EMAIL, new String[]{""});		  
				email.putExtra(Intent.EXTRA_SUBJECT, "Yamba Status");
				email.putExtra(Intent.EXTRA_TEXT, statusText.getText());
				email.setType("message/rfc822");
				startActivity(Intent.createChooser(email, getResources().getString(R.string.chooseEMailClient)));        
			}
		});
	}
}
